<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="供应商" prop="supplierName">
        <el-input
          v-model="queryParams.supplierName"
          placeholder="请输入供应商id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="燃料品名" prop="fuelName">
        <el-input
          v-model="queryParams.fuelName"
          placeholder="请输入燃料品名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="送料车辆" prop="carNum">
        <el-input
          v-model="queryParams.carNum"
          placeholder="请输入送料车辆"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预约送达时间" prop="reservationDate" label-width="120">
        <el-date-picker clearable
          v-model="queryParams.reservationDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择预约送达时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-select v-model="queryParams.state" placeholder="请输入状态" clearable>
          <el-option
            v-for="dict in dict.type.pound_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          :disabled="single"
          @click="handleForm"
        >上传过磅</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleStoreForm"
        >入库</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleCheckForm"
        >质检</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          :disabled="single"
          @click="handleAssayForm"
        >化验</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAssayImport"
        >导入化验结果</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['pound:pound:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['pound:pound:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="poundList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="id" align="center" prop="id" /> -->
      <!-- <el-table-column label="工厂名称" align="center" prop="factoryName" /> -->
      <el-table-column label="供应商" align="center" prop="supplierName" />
      <el-table-column label="燃料品名" align="center" prop="fuelName" />
      <el-table-column label="车辆" align="center" prop="carNum" />
      <el-table-column label="毛重(吨)" align="center" prop="grossWeight" />
      <el-table-column label="皮重(吨)" align="center" prop="tareWeight" />
      <el-table-column label="净重(吨)" align="center" prop="netWeight" />
      <el-table-column label="质检扣杂(吨)" align="center" prop="deductWeight" width="120"/>
      <el-table-column label="合同单价" align="center" prop="fuelContractPrice" />
      <el-table-column label="结算单价" align="center" prop="settlementUnitPrice" />
      <el-table-column label="结算金额" align="center" prop="settlementTotalPrice" />
      <el-table-column label="结算重量" align="center" prop="settlementWeight" />
      <el-table-column label="状态" align="center" prop="state">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pound_status" :value="scope.row.state"/>
        </template>
      </el-table-column>
      <el-table-column label="预约送达时间" align="center" prop="reservationTime" width="180">
        <template slot-scope="scope">
          {{scope.row.reservationTime}}
          <!-- <span>{{ parseTime(scope.row.reservationTime, '{y}-{m}-{d}') }}</span> -->
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleView(scope.row)"
            v-hasPermi="['pound:pound:edit']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['pound:pound:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog title="查看" :visible.sync="viewOpen" width="60%" append-to-body>
      <el-form ref="form" :model="form" label-width="120px">

        <el-tabs v-model="activeName">
            <el-tab-pane label="磅单信息" name="first">
              <el-row>
                <el-col :span="12">
                  <el-form-item label="供应商名称" prop="supplierName">
                    {{form.supplierName}}
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="燃料品名" prop="fuelName">
                    {{form.fuelName}}
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item label="车辆车牌" prop="carNum">
                    {{form.carNum}}
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="预约送达时间" prop="reservationTime">
                    <el-date-picker
                      :disabled="true"
                      v-model="form.reservationTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item label="车辆签到时间" prop="signTime">
                    <el-date-picker
                      :disabled="true"
                      v-model="form.signTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="请选择车辆签到时间">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">

                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item label="毛重" prop="grossWeight">
                    {{form.grossWeight}}
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="皮重" prop="tareWeight">
                    {{form.tareWeight}}
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item label="净重" prop="grossWeight">
                    {{form.netWeight}}
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="扣杂" prop="deductWeight">
                    {{form.deductWeight}}
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="24">
                  <el-form-item label="化验结果" prop="assayResult">
                    <div v-for="(item,index) in form.assayResult" :key="index">
                      <span>{{item.attrName}}：</span>
                      <span>{{item.value}}</span>
                    </div>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item label="结算金额" prop="settlementTotalPrice">
                    {{form.settlementTotalPrice}}
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="结算重量" prop="settlementWeight">
                    {{form.settlementWeight}}
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item label="结算单价" prop="settlementUnitPrice">
                    {{form.settlementUnitPrice}}
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="状态" prop="state">
                    <dict-tag :options="dict.type.pound_status" :value="form.state"/>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-tab-pane>
            <el-tab-pane label="过磅照片" name="second">
              <el-row>
                <el-col :span="24">
                  <el-form-item label="过磅照片" prop="poundPic">
                    <div  style="margin: 10px;display: flex;">
                      <img :src="item"  v-for="(item,index) in form.poundPic" :key="index" style="width: calc(50%);height: 400px;margin: 10px;"></img>
                    </div>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-tab-pane>
            <el-tab-pane label="质检照片" name="third">
              <el-row>
                <el-col :span="24">
                  <el-form-item label="质检照片" prop="qualityPic">
                    <div  style="margin: 10px;display: flex;">
                      <img :src="item"  v-for="(item,index) in form.qualityPic" :key="index" style="width: calc(50%);height: 400px;margin: 10px;"></img>
                    </div>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-tab-pane>
            <!-- <el-tab-pane label="结算信息" name="fourth"></el-tab-pane> -->
          </el-tabs>



      </el-form>
    </el-dialog>

    <!-- 添加或修改磅单信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="供应商名称" prop="supplierName">
              {{form.supplierName}}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="燃料品名" prop="fuelName">
              {{form.fuelName}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="车辆车牌" prop="carNum">
              {{form.carNum}}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="预约送达时间" prop="reservationTime">
              <el-date-picker
                :disabled="true"
                v-model="form.reservationTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="车辆签到时间" prop="signTime">
              <el-date-picker
                :disabled="true"
                v-model="form.signTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择车辆签到时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">

          </el-col>
        </el-row>

        <div style="margin: 10px 0;">
          <div style="padding: 10px;color:royalblue;font-size: 16px;font-weight: 700;">过磅信息</div>
          <el-row>
            <el-col :span="12">
              <el-form-item label="毛重" prop="grossWeight">
                <el-input v-model="form.grossWeight" placeholder="请输入毛重" :disabled="disabled"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="皮重" prop="tareWeight" v-if="form.state >= 2">
                <el-input v-model="form.tareWeight" placeholder="请输入皮重" :disabled="disabled"/>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="过磅照片" prop="poundPic">
                <!-- <el-input v-model="form.poundPic" type="textarea" placeholder="请输入内容" /> -->
                <ImageUpload :limit="9" @input="poundPicCallback" v-model="form.poundPic"></ImageUpload>
              </el-form-item>
            </el-col>
          </el-row>
        </div>


        <div style="margin: 10px 0;" v-if="form.state >=3">
          <div style="padding: 10px;color:royalblue;font-size: 16px;font-weight: 700;">质检信息</div>
          <el-row>
            <el-col :span="12">
              <el-form-item label="扣杂" prop="deductWeight">
                <el-input v-model="form.deductWeight" placeholder="请输入扣杂" :disabled="checkDisabled"/>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="质检照片" prop="qualityPic">
                <ImageUpload :limit="9" @input="qualityPicCallback" v-model="form.qualityPic"></ImageUpload>
              </el-form-item>
            </el-col>
          </el-row>
        </div>

        <div style="margin: 10px 0;" v-if="form.state >=4">
          <div style="padding: 10px;color:royalblue;font-size: 16px;font-weight: 700;">上传化验结果</div>
          <el-row v-for="(item,index) in form.attributeList" :key="index">
            <el-col :span="12">
              <el-form-item :label="item.attrName" :name="item.id">
                <el-input v-model="item.value" placeholder="请输入"  type="number"/>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 化验结果导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url" :disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listPound, getPound, delPound, addPound, updatePound } from "@/api/pound/pound";
import { listAttribute } from "@/api/factory/attribute";
import { getToken } from "@/utils/auth";

export default {
  name: "Pound",
  dicts: ['pound_status'],
  data() {
    return {
      //过磅可用状态
      disabled:false,
      //质检可用状态
      checkDisabled:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 磅单信息表格数据
      poundList: [],
      viewOpen:false,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        factoryId: null,
        supplierId: null,
        fuelId: null,
        carId: null,
        factoryName: null,
        supplierName: null,
        fuelName: null,
        carNum: null,
        reservationTime: null,
        signTime: null,
        weighTime: null,
        storeTime: null,
        poundPic: null,
        grossWeight: null,
        tareWeight: null,
        netWeight: null,
        qualityPic: null,
        deductWeight: null,
        assayResult: null,
        calcRules: null,
        settlementTime: null,
        settlementUnitPrice: null,
        settlementTotalPrice: null,
        settlementWeight: null,
        state: null,
        orderByColumn:'id',
        isAsc:'descending'
      },
      // 表单参数
      form: {
        attributeList:[],
      },
      // 表单校验
      rules: {
        factoryId: [
          { required: true, message: "工厂id不能为空", trigger: "blur" }
        ],
        supplierId: [
          { required: true, message: "供应商id不能为空", trigger: "blur" }
        ],
        fuelId: [
          { required: true, message: "燃料品名id不能为空", trigger: "blur" }
        ],
        carId: [
          { required: true, message: "送料车辆id不能为空", trigger: "blur" }
        ],
        factoryName: [
          { required: true, message: "工厂名称不能为空", trigger: "blur" }
        ],
        supplierName: [
          { required: true, message: "供应商名称不能为空", trigger: "blur" }
        ],
        fuelName: [
          { required: true, message: "燃料品名不能为空", trigger: "blur" }
        ],
        carNum: [
          { required: true, message: "车辆车牌不能为空", trigger: "blur" }
        ],
        state: [
          { required: true, message: "状态：0.待过磅，1.已过磅，2.已入库,3.已回皮,4.已质，5.已化验，6.已结算不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ]
      },
      attributeParams:{
        pageNum: 1,
        pageSize: 100,
        fuelId:0,
      },
      // 化验结果导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/pound/pound/importData"
      },
      activeName: 'first',
    };
  },
  created() {
    this.getList();
  },
  methods: {

    poundPicCallback(e){
      this.form.poundPic = e;
    },
    qualityPicCallback(e) {
      this.form.qualityPic = e;
    },
    /** 查询磅单信息列表 */
    getList() {
      this.loading = true;
      listPound(this.queryParams).then(response => {
        this.poundList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getAttributeList(){
      listAttribute(this.attributeParams).then(response =>{
        //this.form.attributeList = response.rows;
        this.$set(this.form, 'attributeList', response.rows);
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        factoryId: null,
        supplierId: null,
        fuelId: null,
        carId: null,
        factoryName: null,
        supplierName: null,
        fuelName: null,
        carNum: null,
        reservationTime: null,
        signTime: null,
        weighTime: null,
        storeTime: null,
        poundPic: null,
        grossWeight: null,
        tareWeight: null,
        netWeight: null,
        qualityPic: null,
        deductWeight: null,
        assayResult: null,
        calcRules: null,
        settlementTime: null,
        settlementUnitPrice: null,
        settlementTotalPrice: null,
        settlementWeight: null,
        state: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加磅单信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPound(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改磅单信息";
      });
    },
    handleView(row){
      this.reset();
      const id = row.id || this.ids
      getPound(id).then(response => {
        this.form = response.data;
        if(response.data.assayResult){
          this.form.assayResult = JSON.parse(response.data.assayResult);
        }
        if(response.data.poundPic){
          this.form.poundPic = JSON.parse(response.data.poundPic);
        }
        if(response.data.qualityPic){
          this.form.qualityPic = JSON.parse(response.data.qualityPic);
        }
        this.activeName = "first";
        this.viewOpen = true;
      });
    },
    //上传磅单
    async handleForm(row){
      this.reset();
      const id = row.id || this.ids
      const result = await getPound(id);
      const data = result.data;
      if(!(data.state == 0 || data.state == 2)){
        this.$modal.msgError("当前选择的不需要上传过磅信息");
        return;
      }
      this.disabled = false;
      this.attributeParams.fuelId = data.fuelId;
      this.getAttributeList();
      this.form = data;
      this.open = true;
      this.title = "磅单信息";

      this.setPic(data);
    },
    //入库
    handleStoreForm(row){
      this.reset();
      const id = row.id || this.ids
      let that = this;
      getPound(id).then(result=>{
        const data = result.data;
        if(data.state != 1){
          this.$modal.msgError("当前选择的磅单状态无需入库");
          return;
        }
        that.$modal.confirm('确定入库？').then(function() {
          let updateForm = {
            id:id[0],
            state:2
          }
          return updatePound(updateForm);
        }).then(() => {
          that.getList();
          that.$modal.msgSuccess("操作成功");
        }).catch(() => {});
      });


    },
    //质检
    async handleCheckForm(row){
      this.reset();
      const id = row.id || this.ids
      const result = await getPound(id);
      const data = result.data;
      if(data.state != 3){
        this.$modal.msgError("当前选择的无需质检");
        return;
      }
      this.disabled = true;
      this.attributeParams.fuelId = data.fuelId;
      this.form = data;
      this.open = true;
      this.title = "磅单信息";
      this.getAttributeList();
      this.setPic(data);
    },
    //化验
    async handleAssayForm(row){
      this.reset();
      const id = row.id || this.ids
      const result = await getPound(id);
      const data = result.data;
      if(data.state != 4){
        this.$modal.msgError("当前选择的无需化验");
        return;
      }
      this.disabled = true;
      this.checkDisabled = true;
      this.attributeParams.fuelId = data.fuelId;
      this.form = Object.assign({}, this.form, data);
      this.open = true;
      this.title = "磅单信息";
      this.getAttributeList();

      this.setPic(data);
    },
    setPic(data){
      if(data.poundPic){
        let pic = JSON.parse(data.poundPic);
        this.form.poundPic = pic.join(',');
      }
      if(data.qualityPic){
        let pic2 = JSON.parse(data.qualityPic);
        this.form.qualityPic = pic2.join(',');
      }
    },
    handleAssayImport(){
     this.upload.title = "化验结果导入";
     this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.upload.open = false;
      this.$router.push({ path: '/factory-fuel/fuel'});
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            let state = this.form.state;
            //过磅
            if(state == 0){
              if(!this.form.grossWeight){
                this.$modal.msgError("毛重不能为空");
                return;
              }
              if(!this.form.poundPic){
                this.$modal.msgError("请上传过磅照片");
                return;
              }
              this.form.state = 1;
            }
            //回皮
            if(state == 2){
              this.form.state = 3;
            }
            //质检
            if(state == 3){
              if(!this.form.deductWeight){
                this.$modal.msgError("扣杂不能为空");
                return;
              }
              if(!this.form.qualityPic){
                this.$modal.msgError("请上传质检照片");
                return;
              }
              this.form.poundPic = null;
              this.form.state = 4;
            }
            //化验
            if(state == 4){
              //let flag = false;
              let errorMsg = [];
              for (var i = 0; i < this.form.attributeList.length; i++) {
                let item = this.form.attributeList[i];
                if(!item.value || item.value == undefined || item.value == null || item.value == ''){
                  errorMsg.push(item.attrName+"不能为空\n");
                }
              }
              if(errorMsg.length >0){
                this.$modal.msgError(errorMsg.join(","));
                return;
              }
              this.form.poundPic = null;
              this.form.qualityPic = null;
              this.form.state = 5;
            }
            updatePound(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPound(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除磅单信息编号为"' + ids + '"的数据项？').then(function() {
        return delPound(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('pound/pound/export', {
        ...this.queryParams
      }, `pound_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
